package service.impl;

import dao.FileDao;
import dao.impl.FileDaoImpl;
import domian.File;
import domian.Paging;
import service.IndexService;

import java.util.List;

public class IndexServiceImpl implements IndexService {
    //文件数据访问层
    FileDao fd = new FileDaoImpl();
    @Override
    public Paging pagingQuery(Integer fileClass, Integer currentPage,Integer pageSize) {
        Paging paging = new Paging();   //创建对象用于返回

        //计算当前分类下共有多少条数据
        Integer totalCount = fd.findCount(fileClass);

        //计算总页数
        Integer totalPage = null;
        if (totalCount%pageSize == 0){
            totalPage = totalCount / pageSize;
        }else {
            totalPage = (totalCount / pageSize) + 1;
        }

        //将页面总页数写入对象
        paging.setTotalPage(totalPage);

        //查找分页后的数据
        List<File> filePage = fd.findFilePage(fileClass, currentPage, pageSize);

        paging.setList(filePage);

        return paging;
    }
}
